package com.my.service.impl;

import com.my.mapper.FolderMapper;
import com.my.pojo.FileInfo;
import com.my.pojo.Folder;
import com.my.service.IFolderService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

@Service
@Data
public class FolderServiceImpl implements IFolderService {

    @Autowired
    private FolderMapper folderMapper;
    @Override
    public boolean saveFolder(Folder folder) {
        return folderMapper.saveFolder(folder);
    }

    @Override
    public List<Folder> selectFolderByName(String folderName) {
        return folderMapper.selectFolderByName(folderName);
    }

    @Override
    public boolean isExistFolder(String folderName) {
        boolean result = false;
        List<Folder> list = folderMapper.selectFolderByName(folderName);
        if(list.size()>0){
            result =true;
        }
        return result;
    }

    @Override
    public boolean createFolder(String folderPath, String foldName) {
        boolean result = false;
        File file = new File(folderPath,foldName);
        if(!file.exists()){
            file.mkdir();
            result =true;
        }
        return result;
    }

}
